import 'package:flutter/material.dart';
import 'package:laksa/screens/chat_screen.dart';
import 'package:laksa/screens/news_screen1.dart';
import 'package:laksa/screens/news_screen2.dart';

class ChatScreenState extends State<ChatScreen>
    with SingleTickerProviderStateMixin {

  TabController _controller;

  int _currentIndex = 0;

  final List<Tab> myTabs = <Tab>[
    new Tab(text: "首页", icon: new Icon(Icons.home, size: 40.0)),
    new Tab(text: "分类", icon: new Icon(Icons.menu, size: 40.0)),
    new Tab(text: "发现", icon: new Icon(Icons.find_replace, size: 40.0)),
    new Tab(text: "购物车", icon: new Icon(Icons.add_shopping_cart, size: 40.0)),
    new Tab(text: "我的", icon: new Icon(Icons.person, size: 40.0)),
  ];

  @override
  void initState() {
    super.initState();
    _controller = new TabController(vsync: this, length: myTabs.length);
  }

  @override
  build(BuildContext context) =>
      new Scaffold(
        appBar: new AppBar(
          leading: new FlatButton(
              onPressed: () {
                Navigator.of(context).pushNamed("/photo");
              },
              child: new Icon(Icons.home)
          ),
          title: new Text('聚游平台'),
          centerTitle: true,
          backgroundColor: const Color(0xffbc0000),
          actions: <Widget>[
            new IconButton(
                icon: new Icon(Icons.add_alarm),
                tooltip: 'Add Alarm',
                onPressed: () {
                  Navigator.pushNamed(context, '/');
                }),
            new PopupMenuButton<String>(
                itemBuilder: (BuildContext context) =>
                <PopupMenuItem<String>>[
                  new PopupMenuItem<String>(
                      value: "price", child: new Text('Sort by price')),
                  new PopupMenuItem<String>(
                      value: "time", child: new Text('Sort by time')),
                ],
                onSelected: (String action) {
                  switch (action) {
                    case "price":
                      break;
                    case "time":
                      break;
                  }
                })
          ],
        ),
        bottomNavigationBar: new BottomNavigationBar(
          currentIndex: _currentIndex,
          items: <BottomNavigationBarItem>[
            new BottomNavigationBarItem(
              icon: new Icon(Icons.home),
              title: new Text('首页'),
              backgroundColor: Colors.deepPurple[500],
            ),
            new BottomNavigationBarItem(
              icon: new Icon(Icons.menu),
              title: new Text('分类'),
              backgroundColor: Colors.deepPurple[500],
            ),
            new BottomNavigationBarItem(
              icon: new Icon(Icons.find_replace),
              title: new Text('发现'),
              backgroundColor: Colors.deepPurple[500],
            ),
            new BottomNavigationBarItem(
              icon: new Icon(Icons.add_shopping_cart),
              title: new Text('购物车'),
              backgroundColor: Colors.deepPurple[500],
            ),
            new BottomNavigationBarItem(
              icon: new Icon(Icons.person),
              title: new Text('我的'),
              backgroundColor: Colors.deepPurple[500],
            ),
          ],
          onTap: (int index) {
            setState(() {
              _currentIndex = index;
            });
            if (index == 0) {
              new NewsScreen1();
            } else if (index == 1) {
              new NewsScreen2();
            }
          },
        ),
//          new TabBar(
//          controller: _controller,
//          labelColor: const Color(0xff000ab0),
//          indicatorColor: const Color(0xfff10ab0),
////          labelStyle: new TextStyle(color: const Color(0xffbc0000)),
//          unselectedLabelColor: const Color(0xfff10ab0),
//          tabs: myTabs,
//        ),
        body: new TabBarView(
          controller: _controller,
          children: [
            new NewsScreen1(),
            new NewsScreen2(),
            new NewsScreen1(),
            new NewsScreen2(),
            new NewsScreen1(),
          ],
        ),
      );
}